<script setup lang="ts">
//获取路由:
// 1.导入路由对象useRoute
// 2.基于useRoute创建route对象
// 3.获取参数
import { ref } from 'vue'
import { useRoute } from 'vue-router'
const route = useRoute()
//通过route.query.参数名获取参数
// const keyWord = ref('');
// keyWord.value = route.query.query as string;
// console.log(route.query);

//动态路由获取参数->通过route.params.参数名获取参数
const myKey = ref('')
console.log(route.params)

myKey.value = route.params.key as string;
</script>

<template>
  <div class="search">
    <!-- 写法1:通过变量获取参数
    <p class="search-keyword">搜索关键字: {{keyWord }}</p>
    写法2:通过$route.query.参数名获取
    <p class="search-keyword">搜索关键字: {{$route.query.query }}</p> -->

    <!-- 动态路由获取参数- -->
    <p class="search-keyword">搜索关键字: {{ myKey }}</p>
    <p class="search-keyword">搜索关键字: {{ $route.params.key }}</p>
    <p>搜索结果:</p>
    <ul>
      <li>.............</li>
      <li>.............</li>
      <li>.............</li>
      <li>.............</li>
    </ul>
  </div>
</template>

<style>
.search {
  width: 400px;
  height: 240px;
  padding: 0 20px;
  margin: 0 auto;
  border: 2px solid #c4c7ce;
  border-radius: 5px;
}
.search .search-keyword {
  color: #b3ed88;
  font-size: 20px;
}
</style>
